package com.zyx.nettypro.netty.sticky.solver;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author Yaxi.Zhang
 * @since 2021/9/24 10:35
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) {
        // 将传入的MessageProtocol转为编码成为ByteBuf
        System.out.println("调用MyMessageEncoder的encode方法......");
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}
